
$(function() {
	initPage();
	initButton();
});


/**
 * 点击事件
 */
function initButton() {

	$("body").on('click','.teatea',function(){
		var param = {};
		param.productId = $(this).attr('productid');
		param.type = $(this).attr('type');
		//跳转
		localStorage.setItem('param',JSON.stringify(param));
		window.location=server_url+"proDetail.do";
	});
}


// 初始化页面
function initPage() {
	//初始化显得是的茶人茶艺在数据库存的type为2
	$.ajax({
		type : "get",
		url : server_url
				+ 'rest/tea/product/getMyRelease.do?ran=' + Math.random(),
		dataType : 'json',
		async : true,
		data : {
			type : 9,
			userId:localStorage.getItem('userid')
		},
		success : function(result) {
			//console.log(result);
			if (result.retCode == '0000') {
				var str = '';
				var proList = result.data;
				if(proList.length>=1){
					//str += '<div class="recommend-box"><div class="recommend-tit">猜你喜欢</div></div><div class="pro-list-b clear">';
					$.each(proList,function(i,n){
						
						//str +='<div class="fl pro-item-b" id="'+n.productid+'" type="'+n.cateid+'"><img src="'+n.pic+'" alt=""><div class="name-box clear"><p class="fr normap">'+n.productname+'</p></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span></div><p class="fr">已售'+n.teaSellNum+'件</p></div></div>';
						//str +='<img src="'+n.pic+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.legalName+'</span><span class="fl color02">'+n.teaIndustry+'</span></div><div class="item-time2 clear"><span class="fl">'+n.teaSex+'/'+n.teaAge+'岁/从业'+n.teaYear+'年/'+n.teaTrip+'</span></div><div class="item-time2 clear"><span class="fl">成交量：'+n.teaSellNum+'</span><span class="fr">月薪面议</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>万元</div><p class="fr">'+n.detailAddress+'</p></div></div>';

						var teaIndustryStr = ''
						var teaIndustrys = n.teaIndustry.split(",");
						$.each(teaIndustrys,function(i,n){
							if(n==0){
								teaIndustryStr += '<span class="fl color02">茶艺师</span>';
							}else if(n==1){
								teaIndustryStr += '<span class="fl color03">评茶员（师）</span>';
							}else if(n==2){
								teaIndustryStr += '<span class="fl color02">制茶师</span>';
							}else if(n==3){
								teaIndustryStr += '<span class="fl color03">茶园园艺工</span>';
							}
						});
						var age = n.teaAge;
						var year = n.teaYear;
						var trip;
						if(n.teaTrip=='0'){
							trip = '不出差';
						}else{
							trip = '可出差';
						}
						//str +='<div class="skill-list clear" type="'+n.cateid+'" productid="'+n.productid+'"><img src="'+n.pic+'" alt="" class="fl"><div class="skill-box fr"><div class="item-det clear"><span class="fl name">'+n.productname+'</span>'+teaIndustryStr+'</div><div class="item-time clear"><span class="fl">女/'+n.teaAge+'岁/从业'+n.teaYear+'年/'+trip+'</span></div><div class="item-time clear"><span class="fl">成交量：'+n.teaSellNum+'</span><span class="fr">月薪面议</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>元</div><p class="fr">'+n.teaLocation+'</p></div></div></div>';
						str +='<div class="list-item clear teatea" type="'+n.cateid+'" productid="'+n.productid+'"><div class="img-box fl"><img src="'+n.pic+'" alt="" class="fl"><p class="con-box">交易成功</p></div><div class="item-r fl"><p class="item-tit">'+n.productname+'</p><div class="item-det clear"><span class="fl color01">有林地</span><span class="fl color02">转让</span><span class="fl color03">整租</span></div><div class="item-time clear"><p class="fl">'+n.coverArea+'亩</p><span class="fr">'+n.teaYear+'年</span></div><div class="num-box clear"><div class="fl">￥<span>'+n.teaPrice+'</span>万元</div>	<p class="fr">'+n.teaLocation+'</p></div></div></div>';
					});
					
				}
				$('#tradingLand').html(str);
			} else{
				showErrorMsg(result.data);
			}
		}
	});
}
